import dayjs from 'dayjs';

export default {
  data() {
    return {
      formData: {
        status: undefined,
        dateRange: [
          dayjs()
            .date(1)
            .toDate(),
          dayjs()
            .date(dayjs().daysInMonth())
            .toDate(),
        ],
      },
      pagination: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      listData: [],
      loading: true,
    };
  },
  filters: {
    dateFilter(val) {
      if (val.length !== 8) {
        return val;
      } else {
        return `${val.substr(0, 4)}-${val.substr(4, 2)}-${val.substr(6, 2)}`;
      }
    },
    timeFilter(val) {
      if (val.length !== 6) {
        return val;
      } else {
        return `${val.substr(0, 2)}:${val.substr(2, 2)}:${val.substr(4, 2)}`;
      }
    },
  },
  mounted() {
    this.getWithDrawRecord();
  },
  methods: {
    async getWithDrawRecord() {
      const { pageNum, pageSize } = this.pagination;
      const { status, dateRange } = this.formData;
      const params = {
        type: 1,
        pageNum,
        pageSize,
        status,
        startDate: dateRange ? dayjs(dateRange[0]).format('YYYYMMDD') : undefined,
        endDate: dateRange ? dayjs(dateRange[1]).format('YYYYMMDD') : undefined,
      };
      if (params.status === undefined) delete params.status;
      if (params.startDate === undefined) delete params.startDate;
      if (params.endDate === undefined) delete params.endDate;
      const { success, data, total } = await this.$api.getWithDrawRecord(params);
      if (success) {
        this.listData = data;
        this.pagination.total = total;
      }
      this.loading = false;
    },
    doSearch() {
      this.pagination.pageNum = 1;
      this.loading = true;
      this.getWithDrawRecord();
    },
    reviewWithdraw(row) {
      this.$confirm('确认要通过此提现审核吗?', '重要提示')
        .then(async() => {
          const { success } = await this.$api.reviewWithdraw(row.id);
          if (success) {
            this.$message.success('审核成功');
            this.getWithDrawRecord();
          }
        })
        .catch(() => {});
    },
    handleSizeChange(num) {},
    handleCurrentChange(num) {
      // -
    },
  },
};
